
/*******************************************************************************
* Analysis
*******************************************************************************/

***** Create graphs ************************************************************

*** vaccination rate over time *************************************************

* Trends in vaccination rate over time
use "$edited/final_data", clear
keep if weekday == 1 // work only with Mondays
keep if sh_dose_1<.

xtset municipality_id date

collapse (mean) sh_dose_? [fweight = population] if gps==1, by(date any_antivax_gps)

format date %td

gen dh = date

local tboxopt ", placement(e) size(vsmall) justification(center) orient(vertical)"

sum sh_dose_1 if date==22676 & any_antivax_gps==1, meanonly
local mtreat =r(mean)
sum sh_dose_1 if date==22676 & any_antivax_gps==0, meanonly
local mcont =r(mean)
local gap = round(`mtreat'-`mcont',0.1)

twoway (connected sh_dose_1 date if any_antivax_gps==1, color(red) lwidth(medthick) msymbol(o) msize(vsmall)) ///
 (connected sh_dose_1 date if any_antivax_gps==0, color(edkblue) lwidth(medthick)  msymbol(oh) msize(vsmall)), scale(1.2) ///
 ytitle("Municipality vaccination rate in % of population" "(at least one dose)") ///
 legend(order(1 "GP signed open letter" 2 "GP did not sign open letter") ///
	size(vsmall) region(lwidth(none)) ring(0)  pos(11) rows(4)) xlabel(,nogrid) xtitle("") ///
	xline(22291 22347 22466 22592 22603 22628, lwidth(*0.5) lpattern(dot)) ///
	text(30 22291 "GPs start vaccinations" `tboxopt')  ///
	text(30 22348 "Concerns about AZ vaccine emerge" `tboxopt')  ///
	text(30 22467 "Vaccinations without registration" `tboxopt')  ///
	text(30 22593 "Introduction of 2G rule" `tboxopt') /// 
	text(30 22604 "Announcement of vaccine mandate" `tboxopt') /// 
	text(30 22629 "Publication of open letter" `tboxopt') ///
	text(71.2 22629.2 "`=ustrunescape("\u23AB")'" "`=ustrunescape("\u23AC")'"  "`=ustrunescape("\u23AD")'", placement(s) size(2)) ///
	text(67.7 22631.5 "7.3 pp." , size(vsmall) justification(left) placement(e)) 

export delimited sh_dose_1 date any_antivax_gps using "$edited/data_figure2.csv", replace	
	
* pdf version
graph export "$output/vaccination_rate_overtime.pdf", replace

* jpg version
graph export "$output/vaccination_rate_overtime.jpg", replace



********************************************************************************
* Regressions with timeline
use "$edited/final_data", clear
keep if weekday == 1

xtset municipality_id date

      
local weight "[pweight=population]"
local pop_res "if gps <=10 & population<=10000"
local covars_ia "i.date i.date#i.near_vaccination_center i.date#i.near_waldorf i.date#c.sh_cases_pre i.date#c.cum_deaths_27dec2020 i.date#c.sh_pop_female i.date#c.sh_pop_0_14 i.date#c.sh_pop_15_29 i.date#c.sh_pop_45_59 i.date#c.sh_pop_60_74 i.date#c.sh_pop_75_99 i.date#c.sh_pop_pflichtschule i.date#c.sh_pop_mededu i.date#c.sh_pop_uni i.date#c.pensions i.date#c.salaries i.date#c.sh_pop_foreign i.date#c.mun_pop i.date#c.mun_pop2 i.date#c.sh_fpo i.date#i.state i.date##i.district_schwaz"

reg sh_dose_1 c.sh_antivax_gps#i.date `covars_ia' `pop_res' `weight', cluster(municipality_id) 
eststo weighted
regsave , ci

gen date = substr(var,1,5)
destring date, replace force
gen dh = date
format date %td
gen coi1 = regexm(var, "sh_antivax_gps")
gen coi2 = regexm(var, "1.near_vaccination_center")
gen coi3 = regexm(var, "1.near_waldorf")

export delimited coef ci_upper ci_lower date if coi1==1 using "$edited/data_figure3.csv", replace	


*** Visualize effect overtime

local tboxopt ", placement(e) size(vsmall) justification(left) orient(vertical)"

twoway (connected coef date if coi1==1, color(edkblue) lwidth(medthick)  msymbol(oh) msize(vsmall) sort(date)) ///
	 (line ci_upper date if coi1==1, color(edkblue) sort(date) lwidth(*0.5) lpattern(dash)) ///
	 (line ci_lower date if coi1==1, color(edkblue) sort(date) lwidth(*0.5) lpattern(dash)), ///
	 ytitle("Effect on vaccination rate (at least one dose)") ///
	 xline(22291 22347 22466 22592 22603 22628, lwidth(*0.5) lpattern(dot)) ///
	 text(-8 22291 "GPs start vaccinations" `tboxopt')  ///
	 text(-8 22348 "Concerns about AZ vaccine emerge" `tboxopt')  ///
	 text(-1.6 22467 "Vaccinations without registration" `tboxopt')  ///
	 text(-1.2 22593 "Introduction of 2G rule" `tboxopt') /// 
	 text(-1.7 22604 "Announcement of vaccine mandate" `tboxopt') /// 
	 text(-1.2 22629 "Publication of open letter" `tboxopt') /// ///	 
	 xtitle("") legend(off) xlabel(,nogrid)
	 
*pdf version
graph export "$output/effect_overtime.pdf", replace

*jpg version
graph export "$output/effect_overtime.jpg", replace

